void xcsv_file_init(void)
{
xcsv_file.is_internal = false;
- xcsv_file.prologue_lines = 0;
- xcsv_file.epilogue_lines = 0;
xcsv_file.field_delimiter = QString();
xcsv_file.field_encloser = QString();
xcsv_file.record_delimiter = QString();
xcsv_file.description = NULL;
xcsv_file.extension = NULL;
- QUEUE_INIT(&xcsv_file.prologue);
- QUEUE_INIT(&xcsv_file.epilogue);
+ xcsv_file.prologue.clear();
+ xcsv_file.epilogue.clear();
QUEUE_INIT(&xcsv_file.ifield);
/* ofield is alloced to allow pointing back at ifields
void
xcsv_prologue_add(char* prologue)
{
- ogue_t* ogp = (ogue_t*) xcalloc(sizeof(*ogp), 1);
-
- ogp->val = prologue;
- ENQUEUE_TAIL(&xcsv_file.prologue, &ogp->Q);
- xcsv_file.prologue_lines++;
+ xcsv_file.prologue.append(prologue);
}
/*****************************************************************************/
void
xcsv_epilogue_add(char* epilogue)
{
- ogue_t* ogp = (ogue_t*) xcalloc(sizeof(*ogp), 1);
-
- ogp->val = epilogue;
- ENQUEUE_TAIL(&xcsv_file.epilogue, &ogp->Q);
- xcsv_file.epilogue_lines++;
+ xcsv_file.epilogue.append(epilogue);
}
static
char* s;
Waypoint* wpt_tmp;
int linecount = 0;
- queue* elem, *tmp;
+ queue* elem;
field_map_t* fmp;
- ogue_t* ogp;
route_head* rte = NULL;
route_head* trk = NULL;
utm_northing = 0;
rtrim(buff);
/* skip over x many lines on the top for the prologue... */
- if ((xcsv_file.prologue_lines) && ((linecount - 1) <
- xcsv_file.prologue_lines)) {
+ if ((linecount - 1) < xcsv_file.prologue.count()) {
continue;
}
* pre-read the file to know how many data lines we should be seeing,
* we take this cheap shot at the data and cross our fingers.
*/
-
- QUEUE_FOR_EACH(&xcsv_file.epilogue, elem, tmp) {
- ogp = (ogue_t*) elem;
- if (strncmp(buff, ogp->val, strlen(ogp->val)) == 0) {
- buff[0] = '\0';
- break;
- }
+ foreach(const QString& ogp, xcsv_file.epilogue) {
+ if (ogp.startsWith(buff)) {
+ buff[0] = '\0';
+ break;
+ }
}
-
if (strlen(buff)) {
wpt_tmp = new Waypoint;
void
xcsv_data_write(void)
{
- queue* elem, *tmp;
- ogue_t* ogp;
time_t time;
struct tm tm;
-// char tbuf[32];
/* reset the index counter */
waypt_out_count = 0;
}
/* output prologue lines, if any. */
- QUEUE_FOR_EACH(&xcsv_file.prologue, elem, tmp) {
- ogp = (ogue_t*) elem;
+ foreach(const QString& line, xcsv_file.prologue) {
// If the XCSV description contains weird characters (like sportsim)
// this is where they get lost.
- QString cout = ogp->val;
+ QString cout = line;
// Don't do potentially expensive replacements if token prefix
// isn't present;
}
/* output epilogue lines, if any. */
- QUEUE_FOR_EACH(&xcsv_file.epilogue, elem, tmp) {
- ogp = (ogue_t*) elem;
- gbfputs(ogp->val, xcsv_file.xcsvfp);
+ foreach(const QString& ogp, xcsv_file.epilogue) {
+ gbfputs(ogp, xcsv_file.xcsvfp);
gbfputs(xcsv_file.record_delimiter, xcsv_file.xcsvfp);
}
}
int options;
} field_map_t;
-/* a queuing struct for prologues / epilogues */
-typedef struct ogue {
- queue Q;
- char* val;
-} ogue_t;
-
/* something to map config file constants to chars */
typedef struct char_map {
const char* key;
bool is_internal; /* bool - is internal (1) or parsed (0) */
- int prologue_lines; /* # of lines to ignore at top of the file */
- int epilogue_lines; /* # of lines to ignore at bottom of file */
-
/* header lines for writing at the top of the file. */
- queue prologue;
+ QStringList prologue;
/* footer lines for writing at the bottom of the file. */
- queue epilogue;
+ QStringList epilogue;
QString field_delimiter; /* comma, quote, etc... */
QString field_encloser; /* doublequote, etc... */
{
queue* elem, *tmp;
field_map_t* fmp;
- ogue_t* ogp;
int internal = 0;
/*
*/
/* destroy the prologue */
- QUEUE_FOR_EACH(&xcsv_file.prologue, elem, tmp) {
- ogp = (ogue_t*)elem;
- if (ogp->val) {
- xfree(ogp->val);
- }
- if (elem) {
- xfree(elem);
- }
- }
+ xcsv_file.epilogue.clear();
/* destroy the epilogue */
- QUEUE_FOR_EACH(&xcsv_file.epilogue, elem, tmp) {
- ogp = (ogue_t*)elem;
- if (ogp->val) {
- xfree(ogp->val);
- }
- if (elem) {
- xfree(elem);
- }
- }
+ xcsv_file.epilogue.clear();
/* destroy the ifields */
QUEUE_FOR_EACH(&xcsv_file.ifield, elem, tmp) {
} else
if (ISSTOKEN(sbuff, "PROLOGUE")) {
- xcsv_prologue_add(xstrdup(&sbuff[9]));
+ xcsv_prologue_add(sbuff + 9);
} else
if (ISSTOKEN(sbuff, "EPILOGUE")) {
- xcsv_epilogue_add(xstrdup(&sbuff[9]));
+ xcsv_epilogue_add(sbuff + 9);
} else
if (ISSTOKEN(sbuff, "ENCODING")) {